home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / infodata / callbook.tar / callbook_1.3 / endian.c < prev    next >
C/C++ Source or Header  |  1990-07-17  |  2KB  |  85 lines

  1. /*
  2.  * Telnet callsign server sources copyright 1989 by Devon Bowen, KA2NRC.
  3.  * You may distribute and modify these files as you please as long as
  4.  * as long as credit to the original creator is given. Please report any
  5.  * bug fixes or modification to bowen@cs.buffalo.edu.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <sys/file.h>
  10.  
  11. main(argc, argv)
  12. int argc;
  13. char **argv;
  14. {
  15.     int field, fi, fo, cc;
  16.     char fsearch[BUFSIZ], fdata[BUFSIZ];
  17.     unsigned short byte2;
  18.     unsigned int byte4;
  19.  
  20.     field = atoi(argv[1]);
  21.  
  22.     sprintf(fsearch, "callsign.%d.search", field);
  23.     sprintf(fdata, "callsign.%d.data", field);
  24.  
  25.     fi = open(fsearch, O_RDONLY);
  26.     fo = open(strcat(fsearch,"_flip"), O_WRONLY | O_CREAT, 0644);
  27.  
  28.     while (cc = read(fi, &byte2, sizeof(byte2))) {
  29.  
  30.         if (cc == -1) {
  31.             fprintf(stderr, "READ ERROR!\n");
  32.             exit(1);
  33.         }
  34.  
  35.         byte2 = ((byte2 & 0xff00) >> 8) | ((byte2 & 0xff) << 8);
  36.  
  37.         if (write(fo, &byte2, sizeof(byte2)) == -1) {
  38.             fprintf(stderr, "WRITE ERROR!\n");
  39.             exit(1);
  40.         }
  41.  
  42.         if ((cc = read(fi , &byte4, sizeof(byte4))) == -1) {
  43.             fprintf(stderr, "READ ERROR!\n");
  44.             exit(1);
  45.         }
  46.  
  47.         byte4 = ((byte4 & 0xff000000) >> 24) |
  48.             ((byte4 & 0x00ff0000) >>  8) |
  49.             ((byte4 & 0x0000ff00) <<  8) |
  50.             ((byte4 & 0x000000ff) << 24);
  51.  
  52.         if (write(fo, &byte4, sizeof(byte4)) == -1) {
  53.             fprintf(stderr, "WRITE ERROR!\n");
  54.             exit(1);
  55.         }
  56.     }
  57.  
  58.     close(fi);
  59.     close(fo);
  60.  
  61.     fi = open(fdata, O_RDONLY);
  62.     fo = open(strcat(fdata,"_flip"), O_WRONLY | O_CREAT, 0644);
  63.  
  64.     while (cc = read(fi, &byte4, sizeof(byte4))) {
  65.  
  66.         if (cc == -1) {
  67.             fprintf(stderr, "READ ERROR!\n");
  68.             exit(1);
  69.         }
  70.  
  71.         byte4 = ((byte4 & 0xff000000) >> 24) |
  72.             ((byte4 & 0x00ff0000) >>  8) |
  73.             ((byte4 & 0x0000ff00) <<  8) |
  74.             ((byte4 & 0x000000ff) << 24);
  75.  
  76.         if (write(fo, &byte4, sizeof(byte4)) == -1) {
  77.             fprintf(stderr, "WRITE ERROR!\n");
  78.             exit(1);
  79.         }
  80.     }
  81.  
  82.     close(fi);
  83.     close(fo);
  84. }
  85.